package  com.syqc.sensor.tdemp

import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.syqc.custom.LeftRightTextView
import com.syqc.entity.OilDay
import com.syqc.monitor.R
import com.syqc.utils.Units

class TempInfoAdapter(private val teamName: String) :
    BaseQuickAdapter<OilDay, BaseViewHolder>(R.layout.item_sensor_day_temp) {
    var precision: String = "2"
    var oilUnit: String = ""
    private val unitTime by lazy { context.getString(R.string.unit_num) }

    init {
        addChildClickViewIds(R.id.ivDayInfo, R.id.lrvTempDown, R.id.lrvTempUp)
    }

    override fun convert(holder: BaseViewHolder, item: OilDay) {
        val position = holder.layoutPosition + 1
        val num = if (position < 10) "0$position" else "$position"
        holder.setText(R.id.tvItemNum, num)
        holder.run {
            item.run {
                getView<LeftRightTextView>(R.id.lrvTempDate).setRightText(day)
                getView<LeftRightTextView>(R.id.lrvTempTeam).setRightText(teamName)

                val lrvUpTimes = getView<LeftRightTextView>(R.id.lrvTempUp)
                lrvUpTimes.setRightText("$upTimes$unitTime  $upTotal$oilUnit")
                lrvUpTimes.nextVisible(upTimes > 0)
                lrvUpTimes.isEnabled = upTimes > 0

                val lrvDownTimes = getView<LeftRightTextView>(R.id.lrvTempDown)
                lrvDownTimes.setRightText("$downTimes$unitTime  $downTotal$oilUnit")
                lrvDownTimes.nextVisible(downTimes > 0)
                lrvDownTimes.isEnabled = downTimes > 0

                val mileStr = if (mile > 1000) {
                    "$mileKm ${Units.km}"
                } else {
                    "$mile ${Units.m}"
                }
                getView<LeftRightTextView>(R.id.lrvTempMile).setRightText(mileStr)
            }
        }
    }
}